/**
 */
package ram_pc.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import ram_pc.FragmentContainer;
import ram_pc.InteractionFragment;
import ram_pc.Lifeline;
import ram_pc.Ram_pcPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Interaction Fragment</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ram_pc.impl.InteractionFragmentImpl#getCovered <em>Covered</em>}</li>
 *   <li>{@link ram_pc.impl.InteractionFragmentImpl#getContainer <em>Container</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class InteractionFragmentImpl extends EObjectImpl implements InteractionFragment
{
  /**
   * The cached value of the '{@link #getCovered() <em>Covered</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getCovered()
   * @generated
   * @ordered
   */
  protected EList<Lifeline> covered;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected InteractionFragmentImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return Ram_pcPackage.Literals.INTERACTION_FRAGMENT;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Lifeline> getCovered()
  {
    if (covered == null)
    {
      covered = new EObjectWithInverseResolvingEList.ManyInverse<Lifeline>(Lifeline.class, this, Ram_pcPackage.INTERACTION_FRAGMENT__COVERED, Ram_pcPackage.LIFELINE__COVERED_BY);
    }
    return covered;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public FragmentContainer getContainer()
  {
    if (eContainerFeatureID() != Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER) return null;
    return (FragmentContainer)eContainer();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetContainer(FragmentContainer newContainer, NotificationChain msgs)
  {
    msgs = eBasicSetContainer((InternalEObject)newContainer, Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER, msgs);
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setContainer(FragmentContainer newContainer)
  {
    if (newContainer != eInternalContainer() || (eContainerFeatureID() != Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER && newContainer != null))
    {
      if (EcoreUtil.isAncestor(this, newContainer))
        throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
      NotificationChain msgs = null;
      if (eInternalContainer() != null)
        msgs = eBasicRemoveFromContainer(msgs);
      if (newContainer != null)
        msgs = ((InternalEObject)newContainer).eInverseAdd(this, Ram_pcPackage.FRAGMENT_CONTAINER__FRAGMENTS, FragmentContainer.class, msgs);
      msgs = basicSetContainer(newContainer, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER, newContainer, newContainer));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case Ram_pcPackage.INTERACTION_FRAGMENT__COVERED:
        return ((InternalEList<InternalEObject>)(InternalEList<?>)getCovered()).basicAdd(otherEnd, msgs);
      case Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER:
        if (eInternalContainer() != null)
          msgs = eBasicRemoveFromContainer(msgs);
        return basicSetContainer((FragmentContainer)otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case Ram_pcPackage.INTERACTION_FRAGMENT__COVERED:
        return ((InternalEList<?>)getCovered()).basicRemove(otherEnd, msgs);
      case Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER:
        return basicSetContainer(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs)
  {
    switch (eContainerFeatureID())
    {
      case Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER:
        return eInternalContainer().eInverseRemove(this, Ram_pcPackage.FRAGMENT_CONTAINER__FRAGMENTS, FragmentContainer.class, msgs);
    }
    return super.eBasicRemoveFromContainerFeature(msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case Ram_pcPackage.INTERACTION_FRAGMENT__COVERED:
        return getCovered();
      case Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER:
        return getContainer();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case Ram_pcPackage.INTERACTION_FRAGMENT__COVERED:
        getCovered().clear();
        getCovered().addAll((Collection<? extends Lifeline>)newValue);
        return;
      case Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER:
        setContainer((FragmentContainer)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case Ram_pcPackage.INTERACTION_FRAGMENT__COVERED:
        getCovered().clear();
        return;
      case Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER:
        setContainer((FragmentContainer)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case Ram_pcPackage.INTERACTION_FRAGMENT__COVERED:
        return covered != null && !covered.isEmpty();
      case Ram_pcPackage.INTERACTION_FRAGMENT__CONTAINER:
        return getContainer() != null;
    }
    return super.eIsSet(featureID);
  }

} //InteractionFragmentImpl
